-
-
Notifications
You must be signed in to change notification settings - Fork 636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve error message for invalid input in Get()
s
#11081
Conversation
Not sure why we had this in the first place # Building wheels and fs_util will be skipped. Delete if not intended. [ci skip-build-wheels]
# Building wheels and fs_util will be skipped. Delete if not intended. [ci skip-build-wheels]
Feedback on the After Error MessageThe "After" error message is clearer. There is still some ambiguity about which input is at fault. Is UnexpectedTargets supposed to be a single object of type Addresses or the Addresses part? I guess it is "obvious" that it is the Addresses part, but just the fact that I had to think about this for a few cycles makes me think it could be clearer still. Is it true that
I am not sure what I am supposed to do with |
re: I see that |
This is the -- But, in a perfect world, I think the error message could look something like this:
I'll see what we can do. |
Yeah I'm not finding a way in Python to automatically what line a constructor call happens at, that is where |
I thought I might be reading it out of context (i.e. that the module was in the code throwing the error), but after I hit comment.
If you can't get the line and just the module you can say, "Exception: Invalid input to |
ty | ||
)), | ||
} | ||
edges.entry_for(&dependency_key).cloned().ok_or_else(|| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has gotten pretty large, and would be good to extract into a helper function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I plan to simplify the union code in a followup.
# Building wheels and fs_util will be skipped. Delete if not intended. [ci skip-build-wheels]
PTAL. The error message was moved from Rust into the Python constructor. PR description is updated. |
And rewrite part of it to use RuleRunner and to have better proximity. # Rust tests and lints will be skipped. Delete if not intended. [ci skip-rust] # Building wheels and fs_util will be skipped. Delete if not intended. [ci skip-build-wheels]
def test_invalid_get() -> None: | ||
# Bad output type. | ||
assert_invalid_get( | ||
lambda: Get(1, str, "bob"), # type: ignore[call-overload, no-any-return] | ||
expected=( | ||
"Invalid Get. The first argument (the output type) must be a type, but given " | ||
f"`1` with type {int}." | ||
), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While these tests are brittle, I argue that's a feature. We know we need better error messages for the engine - this brittleness ensures we don't accidentally revert on the progress made in this PR.
Of course, we can rewrite the test if we want to reword the message.
ty | ||
)), | ||
} | ||
edges.entry_for(&dependency_key).cloned().ok_or_else(|| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I plan to simplify the union code in a followup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Thank you.
# Rust tests and lints will be skipped. Delete if not intended. [ci skip-rust] # Building wheels and fs_util will be skipped. Delete if not intended. [ci skip-build-wheels]
Before:
After:
Note that the stacktrace includes the offending
Get
, including the line and file where it's set. This is because we now eagerly validate in the Python constructor forGet
.We can only apply this new error message for non-union
Get
calls; the engine must handle type errors relating tounions
because Python does not have knowledge ofUnionMembership
in theGet
constructor.Closes #8349.